package com.htfyun.eink.pw.draw.pen.epd.fountain;


import com.htfyun.eink.pw.draw.pen.epd.EPDBaseManager;
import com.htfyun.eink.pw.draw.pen.epd.data.NeoRenderPoint;
import com.htfyun.eink.pw.draw.pen.epd.data.PenHelper;
import com.htfyun.eink.pw.draw.pointer.PWPointer;

import java.util.List;

public class FountainManager extends EPDBaseManager {
    private final FountainParam param = new FountainParam();

    @Override
    public void onDown(PWPointer pointer) {
        addPoint(pointer);
    }

    @Override
    public void onMove(PWPointer pointer) {
        addPoint(pointer);
    }

    @Override
    public void onUp(PWPointer pointer) {
        addPoint(pointer);
    }

    @Override
    public void setStrokeWidth(float strokeWidth) {
        param.setStrokeWidth(strokeWidth);
    }

    private void addPoint(PWPointer point) {

        float pow = (float) Math.pow(point.pressure, param.pressureExponent);

        float result = param.sizeMin + pow * (param.width - param.sizeMin);
        result = result + result;

        NeoRenderPoint renderPoint = createRenderPointerBy(point, result);

        if (renderPoints.size() > 0) {
            NeoRenderPoint previousRenderPoint = renderPoints.get(renderPoints.size() - 1);
            List<NeoRenderPoint> points = PenHelper.generateStrokePoints(previousRenderPoint, renderPoint);
            renderPoints.addAll(points);
        }
        renderPoints.add(renderPoint);

    }

}
